package com.oa.pm.controller;

import com.joneying.common.web.response.Resp;
import com.oa.pm.dto.ItemBankListDTO;
import com.oa.pm.entity.ItemBank;
import com.oa.pm.service.IItemBankService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.joneying.common.annotation.CommonController;
import org.springframework.context.annotation.Description;

import java.util.Date;
import java.util.List;

import org.springframework.web.bind.annotation.RestController;
import com.oa.core.BaseController;

/**
 * @author syb123
 * @since 2019-01-22
 */
@RestController
@RequestMapping("/itemBank")
@Api(description = "试题库表模块")
public class ItemBankController extends BaseController {

    private final IItemBankService itemBankService;

    @Autowired
    public ItemBankController(IItemBankService itemBankService) {
        this.itemBankService = itemBankService;
    }

    @GetMapping("/list")
    @CommonController
    @Description("查询列表")
    @ApiOperation(value = "查询")
    public Resp findItemBankList(ItemBankListDTO itemBankListDTO) {
        return new Resp().success(itemBankService.findItemBankList(itemBankListDTO));
    }


    /**
     * 新增
     *
     * @return Resp
     */
    @PostMapping("/add")
    @CommonController
    @Description("新增")
    @ApiOperation(value = "新增")
    public Resp add(@ApiParam("文件夹名称") @RequestParam("itemBankName") String itemBankName, @ApiParam("类别") @RequestParam("type") Integer type) {
        ItemBank itemBank = new ItemBank();
        itemBank.setCreateTime(new Date());
        itemBank.setFolderName(itemBankName);
        itemBank.setType(type);
        if (itemBankService.insert(itemBank)) {
            return new Resp().success();
        } else {
            return new Resp().failure();
        }
    }

    /**
     * 根据Id修改
     *
     * @param itemBank ItemBank
     * @return Resp
     */
//    @PutMapping("/update")
//    @CommonController
//    @Description("根据id修改")
//    @ApiOperation(value = "根据id修改")
//    public Resp update(@ApiParam(value = "试题库表对象") @RequestBody(required = false) ItemBank itemBank) {
//        if (itemBankService.updateById(itemBank)) {
//            return new Resp().success();
//        } else {
//            return new Resp().failure();
//        }
//    }
}
